package com.lucher.mes.quartz;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component("StartupListener")
public class InitSystemJobsListener implements ApplicationListener<ContextRefreshedEvent> {
    private int runTime = 0;
 
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        runTime++;
        if (2 == runTime) {
            // 获取spring管理的Bean
            ApplicationContext context = event.getApplicationContext();
            QuartzManager quartzJobManager = (QuartzManager) context.getBean("quartzManager");
            quartzJobManager.loadJobs();
        }
    }
}
